package cn.biplam.front.htmlscript.script;

import cn.biplam.front.template.base.Radio;

/**
 * 选择类型的输入控件（如：radio,checkbox,input）事件绑定
 * @author XiaoRuxing Jul 28, 20097:49:08 PM
 * @version 1.0
 */
public class ScriptSelectInput {

	/**
	 *  选中radio组中指定选项
	 * @param radioName   radio名称
	 * @param radioValue  需要选择的值
	 * @return 选中radio组中指定选项的脚本
	 */
	public static String getRadioSelect(String radioName,String radioValue){
		String unCheckId = Radio.getUnCheckedID(radioName, radioValue);
		String unChecked = "$('"+unCheckId+"')";
		StringBuilder sp = new StringBuilder();
		sp.append("if("+unChecked+"){");
		sp.append(unChecked);
		sp.append(".onclick();};");
		return sp.toString();
	}
	
	/**
	 *  radio选项组中指定选项被选中后执行指定代码
	 * @param radioName   radio名称
	 * @param radioValue  指定选项的值
	 * @param script      要执行的脚本
	 * @return radio选项组中指定选项被选中后执行指定代码
	 */
	public static String radioSelectSubmit(String radioName,
			String radioValue,String script){
		String checkId = Radio.getCheckID(radioName, radioValue);
		String checked = "$('"+checkId+"')";
		StringBuilder sp = new StringBuilder();
		sp.append("if("+checked+".style.visibility=='inherit'){");
		sp.append(script);
		sp.append("};");
		return sp.toString();
	}
	
	/**
	 *  
	 * @param script 要执行的代码
	 * @return 输入框中用户按下回车键执行指定代码
	 */
	public static String inputEnterKeyDown(String script){
		StringBuilder sp = new StringBuilder();
		sp.append("if(event.keyCode==13){");
		sp.append(script);
		sp.append("}");
		return sp.toString();
	}
}

